package gui.applets;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
public class AppletTextArea extends Applet{
	Button btn1=new Button("Text Area 1");
	Button btn2=new Button("Text Area 2");
	Button btn3=new Button("Text Area 3");
	Button btn4=new Button("Text Area 4");
	
	TextArea ta1=new TextArea("Ta1",1,30);
	TextArea ta2=new TextArea("Ta2",4,30);

	TextArea ta3=new TextArea("Ta3",1,30,TextArea.SCROLLBARS_NONE);
	TextArea ta4=new TextArea("Ta4",10,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
	TextArea ta5=new TextArea("Ta5",4,30,TextArea.SCROLLBARS_HORIZONTAL_ONLY);
	TextArea ta6=new TextArea("Ta6",10,10,TextArea.SCROLLBARS_BOTH);
	
	public void init(){
		this.btn1.addActionListener(new Btn1());
		this.add(this.btn1);
		this.add(this.ta1);
		
		this.btn2.addActionListener(new Btn2());
		this.add(this.btn2);
		this.add(this.ta2);
		
		this.btn3.addActionListener(new Btn3());
		this.add(this.btn3);

		
		this.btn4.addActionListener(new Btn4());
		this.add(this.btn4);
		
		this.add(this.ta3);
		this.add(this.ta4);
		this.add(this.ta5);
		this.add(this.ta6);
	}
	
	class Btn1 implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			ta5.append(ta1.getText()+"\n");
			
		}
		
	}

	class Btn2 implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			ta2.setText("Insert by Button 2");
			ta2.append(": "+ta1.getText());
			ta5.append(ta2.getText()+"\n");
		}
		
	}

	class Btn3 implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			String s="Replacement";
			ta2.replaceRange(s, 3, 3+s.length());
		}
		
	}

	class Btn4 implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			ta2.insert("Insert", 10);
		}
		
	}
	
	public static void main(String[]args){
		AppletTextArea ta=new AppletTextArea();
		Frame frame=new Frame("TextArea");
		frame.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
		frame.add(ta,BorderLayout.CENTER);
		frame.setSize(300,750);
		ta.init();
		frame.setVisible(true);
	}
}
